import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueDevTools()],

  // 解决跨域问题
  server: {
    /*   host: '0.0.0.0',
     port: 8888, */
    proxy: {
      '/api': {
        target: 'http://localhost:8080/',
        // secure: false, // 请求是否为https
        changeOrigin: true, //是否开启跨域，值为 true 就是开启， false 不开启
        rewrite: (path) => path.replace(/^\/api/, ''), //api替换为'',
      },
    },
  },

  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
